import 'package:ati_package/core/extension/ati_widgets_extension.dart';
import 'package:ati_package/core/utils/ati_color.dart';
import 'package:ati_package/core/utils/ati_font.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class AtiScaffold extends StatefulWidget {
  final String? title;
  final Color? titleColor;
  final String? rigthTitle;
  final VoidCallback? rigthOnTap;
  final Widget? body;
  final bool? showBack;
  final Color? barBgColor;
  final bool? extendBodyBehindAppBar;
  final Widget? actionWidget;

  const AtiScaffold({
    super.key,
    this.title,
    this.titleColor,
    this.rigthTitle = '',
    this.rigthOnTap,
    this.body,
    this.showBack = true,
    this.barBgColor = const Color(0xFFFFFFFF),
    this.extendBodyBehindAppBar = false,
    this.actionWidget,
  });

  @override
  State<AtiScaffold> createState() => _AtiScaffoldState();
}

class _AtiScaffoldState extends State<AtiScaffold> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      extendBodyBehindAppBar: widget.extendBodyBehindAppBar!,
      appBar: buildAppBar(),
      backgroundColor: AtiColor.pageColor,
      body: widget.body,
    );
  }

  buildAppBar() {
    return AppBar(
      backgroundColor: widget.barBgColor,
      leadingWidth: 55.r,
      leading: widget.showBack == true
          ? Padding(
              padding: EdgeInsets.only(left: 16.r, right: 16.r),
              child: InkWell(
                onTap: () {
                  Get.back();
                },
                child: Image.asset(
                  width: 16.r,
                  height: 16.r,
                  color: widget.titleColor,
                  'assets/images/common/ati_back_icon.png',
                  package: 'ati_package',
                  fit: BoxFit.contain,
                ),
              ),
            )
          : null,
      title: Text(
        widget.title ?? '',
        style: TextStyle(
          fontSize: 18.r,
          fontWeight: FontWeight.w600,
          color: widget.titleColor,
        ),
      ),
      actions: [
        Container(
          margin: EdgeInsets.only(right: 16.r),
          child:
              widget.actionWidget ??
              Text(
                widget.rigthTitle!,
                style: TextStyle(
                  color: widget.titleColor ?? AtiColor.textColor1,
                  fontSize: AtiFont.font12,
                ),
              ).addTapGesture(onTap: widget.rigthOnTap ?? () {}),
        ),
      ],
    );
  }
}
